package com.yanqu.road.server.cmd.union.cross.parergon;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.Parergon;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.xiaomian.XiaoMianModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_PARERGON_BARGAIN_FROM_CROSS, desc = "砍价跨服返回")
public class BargainFromCrossCmd extends AbstractCommand {

    private Parergon.BargainRespMsg respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = Parergon.BargainRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (respMsg.getRet() == 0) {
            player.notifyListener(eGamePlayerEventType.UnionBargain.getValue(), 1);
            player.notifyListener(eGamePlayerEventType.TotalUnionBargainTime.getValue(),1);
            //平台接口加次数
            player.getModule(XiaoMianModule.class).addUnionBargainTimes(1);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        player.sendPacket(ClientProtocol.U_UNION_PARERGON_BARGAIN, respMsg.toBuilder());
    }
}
